package com.itheima;

import com.itheima.dao.imple.UserDao;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration//说明当前类是配置类 作用类似 applicationContext.xml
@ComponentScan//扫描项目中的所有bean类（添加了@Component
@EnableAspectJAutoProxy
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        User user = (User) context.getBean("User.class");
        //上二行作用等同与User user=new User();
        System.out.println(user);
       UserService userService = (UserService) context.getBean("userService.class");
       boolean flag=userService.login("张三","123");
       if(flag){
           System.out.println("登录成功");
       }else {
           System.out.println("登录失败");
       }
        UserDao userDao = (UserDao) context.getBean("userDao.class");
       userDao.update();
       userDao.insert();
       userDao.delete();
       userDao.select();
    }
}
